﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp.委托
{
    public delegate void MyDelegate(string title);

    public delegate void MyDelegateDemo2(int a,int b);
    public delegate int MyDelegateDemo3(int a, int b);

    public class Demo1
    {
        private void ShowName(string name)
        {
            Console.WriteLine($"show name {name}");
        }

        public  void TestDelegate() 
        {
            MyDelegate myDelegate = new MyDelegate(ShowName);

            myDelegate("张三");
        }


        public MyDelegateDemo2 TestDelegate2 = delegate (int a, int b)
        {
            Console.WriteLine($"a={a},b={b}");
        };


        private void TestDelegate4(int a, int b)
        {
            var c = a + b;
            Console.WriteLine($"cccccccc={c}");
        }

        public void TestDelegate3(int a, int b)
        { 
            MyDelegateDemo2 myDelegate3 = TestDelegate4; 
            myDelegate3(a, b);
        }


        private int TestDelegate5(int a, int b)
        {
            var c = a + b; 
            return c;
        }
        public void TestDelegate55(int a, int b)
        {
            MyDelegateDemo3 myDelegate5 = TestDelegate5;
            var result = myDelegate5(a, b);
            Console.WriteLine($"result={result}");
        }

    }
}
